@@ -9,6 +9,10 @@ module WebRequestConcern |
||
| 9 | 9 |
errors.add(:base, "user_agent must be a string") unless options['user_agent'].is_a?(String) |
| 10 | 10 |
end |
| 11 | 11 |
|
| 12 |
+ if options['disable_ssl_verification'].present? and not [true, false].include? options['disable_ssl_verification'] |
|
| 13 |
+ errors.add(:base, "if provided, disable_ssl_verification must be a boolean") |
|
| 14 |
+ end |
|
| 15 |
+ |
|
| 12 | 16 |
unless headers(options['headers']).is_a?(Hash) |
| 13 | 17 |
errors.add(:base, "if provided, headers must be a hash") |
| 14 | 18 |
end |
@@ -21,7 +25,13 @@ module WebRequestConcern |
||
| 21 | 25 |
end |
| 22 | 26 |
|
| 23 | 27 |
def faraday |
| 24 |
- @faraday ||= Faraday.new { |builder|
|
|
| 28 |
+ faraday_options = {
|
|
| 29 |
+ ssl: {
|
|
| 30 |
+ verify: !options['disable_ssl_verification'] |
|
| 31 |
+ } |
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ @faraday ||= Faraday.new(faraday_options) { |builder|
|
|
| 25 | 35 |
builder.headers = headers if headers.length > 0 |
| 26 | 36 |
|
| 27 | 37 |
builder.headers[:user_agent] = user_agent |
@@ -62,6 +62,23 @@ shared_examples_for WebRequestConcern do |
||
| 62 | 62 |
agent.options['basic_auth'] = ["blah"] |
| 63 | 63 |
expect(agent).not_to be_valid |
| 64 | 64 |
end |
| 65 |
+ |
|
| 66 |
+ it "should validate disable_ssl_verification" do |
|
| 67 |
+ agent.options['disable_ssl_verification'] = nil |
|
| 68 |
+ expect(agent).to be_valid |
|
| 69 |
+ |
|
| 70 |
+ agent.options['disable_ssl_verification'] = true |
|
| 71 |
+ expect(agent).to be_valid |
|
| 72 |
+ |
|
| 73 |
+ agent.options['disable_ssl_verification'] = false |
|
| 74 |
+ expect(agent).to be_valid |
|
| 75 |
+ |
|
| 76 |
+ agent.options['disable_ssl_verification'] = 'blah' |
|
| 77 |
+ expect(agent).not_to be_valid |
|
| 78 |
+ |
|
| 79 |
+ agent.options['disable_ssl_verification'] = 51 |
|
| 80 |
+ expect(agent).not_to be_valid |
|
| 81 |
+ end |
|
| 65 | 82 |
end |
| 66 | 83 |
|
| 67 | 84 |
describe "User-Agent" do |
@@ -88,4 +105,15 @@ shared_examples_for WebRequestConcern do |
||
| 88 | 105 |
expect(agent.user_agent).to eq('Override')
|
| 89 | 106 |
end |
| 90 | 107 |
end |
| 108 |
+ |
|
| 109 |
+ describe "#faraday" do |
|
| 110 |
+ it "should enable SSL verification by default" do |
|
| 111 |
+ expect(agent.faraday.ssl.verify).to eq(true) |
|
| 112 |
+ end |
|
| 113 |
+ |
|
| 114 |
+ it "should disable SSL verification if disable_ssl_verification option is true" do |
|
| 115 |
+ agent.options['disable_ssl_verification'] = true |
|
| 116 |
+ expect(agent.faraday.ssl.verify).to eq(false) |
|
| 117 |
+ end |
|
| 118 |
+ end |
|
| 91 | 119 |
end |